package com.xujiang.myblog.netserver;

import com.xujiang.myblog.model.AccessToken;
import com.xujiang.myblog.model.Data;
import com.xujiang.myblog.model.HeadPicture;
import com.xujiang.myblog.model.Login;
import com.xujiang.myblog.model.LoginResult;

import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import rx.Observable;

/**
 * Created by xujiang on 2017/4/19.
 */

public interface UserService {

    @POST("/api/user/register")
    Observable<AccessToken<Data>> register(@Header("account") String account,
                                           @Header("password") String password, @Body Login login);

    @POST("/api/user/login")
    Observable<AccessToken<LoginResult>> login(@Header("account") String account,
                                               @Header("password") String password, @Body Login login);


    /**
     * 上传头像
     * @param file 文件 {@link MultipartBody.Part}
     * @return {@link ResponseBody}
     * @see <a href="https://futurestud.io/blog/retrofit-2-how-to-upload-files-to-server">how to upload</a>
     */
    @Multipart
    @POST("/api/files/headpicture")
    Observable<AccessToken<HeadPicture>> headPortraitUpload(
            @Part MultipartBody.Part file);


    /**
     * 上传图片
     *
     * */
    @Multipart
    @POST("/api/files/picture")
    Observable<AccessToken<HeadPicture>> PictureUpload(@Part MultipartBody.Part file);

}
